﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Admin.Presentation.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class PagesController : Controller
    {
        [AppendLayoutViewModel]
        public ActionResult Index()
        {
            
            var model = Business.Pages.Index.PageLoad();
            ViewBag.Message = Request["msg"];
            return View(model);
        }

        public JsonResult GridLoad(DataTransfer.GridLoadInput gridinput)
        {
            var model = Business.Pages.Index.GridLoad(gridinput);
            return Json(model);
        }

        [AppendLayoutViewModel]
        public ActionResult Create(int id)
        {
            
            var model = Business.Pages.Create.PageLoad(id);
            return View(model);
        }

        public JsonResult Save(Adams.Admin.DataTransfer.Pages.Create.FormInput input)
        {
            var model = Business.Pages.Create.Save(input);
            return Json(model);
        }

        public RedirectResult Delete(int id)
        {
            Business.Pages.Index.Delete(id);
            var model = new { Deleted = true };
            return Redirect("/Pages?msg=2");
        }

        public JsonResult GetPagesBySearch(string term)
        {
            var model = Business.Pages.Common.GetPagesBySearch(term);
            return Json(model, JsonRequestBehavior.AllowGet);
        }
    }
}
